home *** CD-ROM | disk | FTP | other *** search
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 14
- #HS,1,4,80,25,11,1
- #C4,R5
-
- ~W~IOperations On Objects~Y~I
-
- Usually, the next step in program design is to define the allowable
- operations on each of the objects. This will enable us to determine the
- set of macros and functions that will make up the ~Sinterface into each file
- in the program.~s
-
- #WN
- I have provided ~R~Imore operations ~Y~Ion objects than are used in Space
- Attackers. This is ~M~Inot usually advisable ~Y~Ibecause it increases program size
- unnecessarily. However, I have attempted to anticipate some of the needs
- you might have in using this code and written some extra macros and
- functions that you might find helpful.
-
-
- #WN
- ~W~IA point~Y~I
-
- Since the point type is a basic component of most of the more complex types
- in this game, we'll list the operations on a point first.
-
- #WN
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 15
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IFigure 7.3~Y~I
- Operations on a point
-
- 1. Set the point.
- 2. Set the point's row.
- 3. Set the point's column.
- 4. Get the point's row.
- 5. Get the point's column.
-
-
- #WN
- At this time we won't discuss the actual algorithms that will be used to
- implement the operations listed above. That will be done in the next
- chapter when we write the code.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 16
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IThe character~Y~I
-
- As previously stated, we will be consolidating the features that are
- common to both attackers and the defender so that we can reuse some of the
- code. The allowable operations on a character are shown in Figure 7.4,
- which begins on the next page.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 17
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IFigure 7.4~Y~I
- Operations on a character
-
- 1. Set the character's position.
- 2. Set the character's row
- 3. Set the character's column.
- 4. Set the character's bitmap.
- 5. Set the height and width of the character's bitmap.
- 6. Set the character's bullet.
- 7. Set the row and column of the character's bullet.
- 8. Set the direction of the character's bullet.
- 9. Set the color of the character's bullet.
- 10. Tell the character whether or not it has a bullet.
- 11. Tell the character whether it's alive or dead.
- 12. Set the character's move increment.
- 13. Get the character's row
- 14. Get the character's column.
- 15. Get the character's bitmap.
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 18
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IFigure 7.4 (cont)~Y~I
- Operations on a character
-
- 16. Get the height and width of the character's bitmap.
- 17. Get the character's bullet.
- 18. Get the row and column of the character's bullet.
- 19. Get the direction of the character's bullet.
- 20. Ask the character if it has a bullet.
- 21. Get the color of the character's bullet.
- 22. Ask the character whether it's alive or dead.
- 23. Get the character's move increment.
-
-
- #WN
- Notice that some of the operations on a character are the same as the
- operations on a point. That's because the member ~W~Icurrent_position ~Y~Iin the
- character is of type point. The operations on ~W~Icurrent_position~Y~I, such as
- setting the row of the upper left corner of the bitmap, will be
- implemented by just calling the appropriate point operation, such as
- ~W~Iset_point_row()~Y~I.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 19
- #HS,1,4,80,25,11,1
- #C4,R5
-
- ~W~IA bullet~Y~I
-
- The allowable operations on a bullet are shown in Figure 7.5. Like a
- character, a bullet will "inherit" some of the point operations because it
- has a member of type point.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 20
- #HS,1,4,80,25,11,1
- #C4,R5
-
- ~W~IFigure 7.5~Y~I
- Operations on a bullet
-
- ~W~I 1. Set the bullet's position.
- 2. Set the row of the bullet.
- 3. Set the column of the bullet.
- 4. Tell the bullet whether or not it exists.
- 5. Set the color of the bullet.
- 6. Set the direction of the bullet.
- 7. Get the row of the bullet.
- 8. Get the col of the bullet.
- 9. Ask the bullet if it exists.
- 10. Get the color of the bullet.
- 11. Get the direction of the bullet.
- ~Y~I 12. Draw the bullet.
- 13. Erase the bullet.
- 14. Move the bullet.
- 15. Test to see if the bullet has hit something.
-
- #BO,4,20,78,23,7,1,0,2,15,5
- The first eleven operation on a bullet are simple enough to be
- implemented as macros.
-
- #C4,R5
-
- ~W~IFigure 7.5~Y~I
- Operations on a bullet
-
- 1. Set the bullet's position.
- 2. Set the row of the bullet.
- 3. Set the column of the bullet.
- 4. Tell the bullet whether or not it exists.
- 5. Set the color of the bullet.
- 6. Set the direction of the bullet.
- 7. Get the row of the bullet.
- 8. Get the col of the bullet.
- 9. Ask the bullet if it exists.
- 10. Get the color of the bullet.
- 11. Get the direction of the bullet.
- ~W~I 12. Draw the bullet.
- 13. Erase the bullet.
- 14. Move the bullet.
- 15. Test to see if the bullet has hit something.
- ~Y~I
-
- #BO,4,7,78,9,7,1,0,2,15,5
- Operations 12-15 will be written as functions.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 21
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IThe player~Y~I
-
- The image of the player will be a tank-like gun that we can move across
- the bottom of the screen. It must also be able to fire at the attackers.
- Figure 7.6 shows the allowable operations on a player.
-
-
- ~W~IFigure 7.6~Y~I
- Allowable operations on a player
-
- 1. Set the player's position.
- 2. Set the player's row
- 3. Set the player's column.
- 4. Set the player's direction.
- 5. Set the player's bitmap.
- 6. Set the height and width of the player's bitmap.
- 7. Set the player's bullet.
- 8. Set the row and column of the player's bullet.
- 9. Set the direction of the player's bullet.
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 22
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IFigure 7.6 (cont)~Y~I
- Allowable operations on a player
-
- 10. Set the color of the player's bullet.
- 11. Tell the player whether it's alive or dead.
- 12. Set the player's move increment.
- 13. Get the player's row
- 14. Get the player's column.
- 15. Get the player's direction.
- 16. Get the player's bitmap.
- 17. Get the height and width of the player's bitmap.
- 18. Get the player's bullet.
- 19. Get the row and column of the player's bullet.
- 20. Get the direction of the player's bullet.
- 21. Get the color of the player's bullet.
- 22. Ask the player whether it's alive or dead.
- 23. Get the player's move increment.
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 23
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IFigure 7.6 (cont)~Y~I
- Allowable operations on a player
-
- 24. Initialize the player.
- 25. Draw the player.
- 26. Move the player.
- 27. Shoot the player's gun.
-
- #WN
- Operations 1-23 will be done with macros. The rest will need to be
- implemented as functions.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 24
- #HS,1,4,80,25,11,1
- #C4,R5
-
- ~W~IThe attacker~Y~I
-
- We also need to know what operations are valid on an attacker. As with
- the operations on a player, some of the attacker operations will be
- implemented as macros and some will be written as functions. Figure 7.7
- shows the allowable operations on an attacker.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 25
- #HS,1,4,80,25,11,1
- #C4,R5
-
- ~W~IFigure 7.7~Y~I
- Operations on an Attacker
-
- 1. Set the attacker's position.
- 2. Set the attacker's row
- 3. Set the attacker's column.
- 4. Set the attacker's direction.
- 5. Tell the attacker whether or not it's in a position to
- shoot.
- 6. Set the attacker's bitmap.
- 7. Set the height and width of the attacker's bitmap.
- 8. Set the attacker's bullet.
- 9. Set the row and column of the attacker's bullet.
- 10. Set the direction of the attacker's bullet.
- 11. Set the color of the attacker's bullet.
- 12. Tell the attacker whether or not it has a bullet.
- 13. Tell the attacker whether it's alive or dead.
-
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 26
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IFigure 7.7 (cont)~Y~I
- Operations on an Attacker
-
- 14. Set the attacker's move increment.
- 15. Get the attacker's row
- 16. Get the attacker's column.
- 17. Get the attacker's direction.
- 18. Get the attacker's bitmap.
- 19. Get the height and width of the attacker's bitmap.
- 20. Get the attacker's bullet.
- 21. Get the row and column of the attacker's bullet.
- 22. Get the direction of the attacker's bullet.
- 23. Ask the attacker if it has a bullet.
- 24. Get the color of the attacker's bullet.
- 25. Ask the attacker whether it's alive or dead.
- #WP
- %
- #EF
- #T15,1,Chapter 7 Designing Space Attackers Pg. 27
- #HS,1,4,80,25,11,1
- #C4,R5
- ~W~IFigure 7.7 (cont)~Y~I
- Operations on an Attacker
-
- 26. Get the attacker's move increment.
- 27. Initialize the attacker.
- 28. Draw the attacker.
- 29. Move the attacker.
- 30. Shoot the attacker's gun.
- 31. Ask the attacker whether or not it's in a position to
- shoot.
-
- #WP
- #X